package eu.webhib.webblog.gui.controller;

import eu.webhib.frmwrk.jsf.utils.JsfUtil;
import eu.webhib.webblog.gui.application.GuiApplication;
import eu.webhib.webblog.gui.application.SessionMoveIntf;
import javax.servlet.http.*;
import javax.faces.bean.*;
import org.apache.log4j.Logger;

@ManagedBean(name = GuiApplication.sessionDataObjectName)
@SessionScoped
public class SessionData implements SessionMoveIntf {

   private static final Logger log = Logger.getLogger(SessionData.class);
   //
   private String historyPage;

   // is triggered by reference in template.xhtml
   public SessionData() {
      HttpServletRequest req = JsfUtil.getRequest();
      log.info("SessionData SessionId: " + req.getSession().getId());
      GuiApplication.initContextURLs(req);
      // default for history page
      historyPage = "";
   }

   // URL Handling  ------------------------------------------------------------
   //
   // is used by template.xhtml
   public String getBaseUrl() {
      return GuiApplication.getBaseUrl();
   }

   //
   // history page mechanism
   //
   public void setHistoryPage(String pagePath) {
      log.info("setHistoryPage: " + pagePath);
      this.historyPage = pagePath;
   }

   public String getHistoryPage() {
      log.info("getHistoryPage: " + historyPage);
      return historyPage;
   }

   //
   // General actions
   //
   public String continueHistoryAction() {
      JsfUtil.sendRedirect(GuiApplication.getHistroyPageURI());
      return null;
   }
}
